﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using MigratorUI.Replayer.Commands;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

namespace MigratorUI.Replayer
{
    public class Replayer
    {
        public Replayer(string fileName)
        {
            this.LoadFile(fileName);
        }

        public void ReplaySimulation()
        {
            foreach (Command command in commands)
            {
                Console.WriteLine("[REPLAYER] Executing a " + command.GetType().Name + " command.");
                command.Execute();
            }
        }

        public void LoadFile(string fileName)
        {           
            FileStream fs = File.OpenRead(fileName);
            IFormatter formatter = new BinaryFormatter();
            commands = (List<Command>)formatter.Deserialize(fs);
            fs.Close();
        }

        private List<Command> commands = new List<Command>();
    }
}
